﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using Joyintech.IDAL.inpiao365;
using Joyintech.DBUtility;//请先添加引用

namespace Joyintech.SQL2008DAL.inpiao365
{
    /// <summary>
    /// 数据访问类movieOnTheater_DAL。
    /// </summary>
    public partial class movieOnTheater_DAL : AbstractDAL, ImovieOnTheater_DAL
    {
        public movieOnTheater_DAL()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int MovieId, int TheaterId)
        {
            Database db = this.CreateDatabase();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from movieOnTheater where MovieId=@MovieId and TheaterId=@TheaterId ");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "MovieId", DbType.Int32, MovieId);
            db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, TheaterId);
            int cmdresult;
            object obj = ExecuteScalar(db, dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Joyintech.Model.inpiao365.movieOnTheater model, DbTransaction trans = null)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into movieOnTheater(");
            strSql.Append("MovieId,MovieName,Director,ToStar,MovieType,Country,Trailer,ReleaseDate,MovieContent,MovieBehind,MovieLogo,MovieStills,MoviePrice,CityId,TheaterId,TheaterName,AreaId,MovieSeatTime,ScreeningsId,Price)");

            strSql.Append(" values (");
            strSql.Append("@MovieId,@MovieName,@Director,@ToStar,@MovieType,@Country,@Trailer,@ReleaseDate,@MovieContent,@MovieBehind,@MovieLogo,@MovieStills,@MoviePrice,@CityId,@TheaterId,@TheaterName,@AreaId,@MovieSeatTime,@ScreeningsId,@Price)");
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "MovieId", DbType.Int32, model.MovieId);
            db.AddInParameter(dbCommand, "MovieName", DbType.String, model.MovieName);
            db.AddInParameter(dbCommand, "Director", DbType.String, model.Director);
            db.AddInParameter(dbCommand, "ToStar", DbType.String, model.ToStar);
            db.AddInParameter(dbCommand, "MovieType", DbType.String, model.MovieType);
            db.AddInParameter(dbCommand, "Country", DbType.String, model.Country);
            db.AddInParameter(dbCommand, "Trailer", DbType.Int32, model.Trailer);
            db.AddInParameter(dbCommand, "ReleaseDate", DbType.DateTime, model.ReleaseDate);
            db.AddInParameter(dbCommand, "MovieContent", DbType.String, model.MovieContent);
            db.AddInParameter(dbCommand, "MovieBehind", DbType.String, model.MovieBehind);
            db.AddInParameter(dbCommand, "MovieLogo", DbType.String, model.MovieLogo);
            db.AddInParameter(dbCommand, "MovieStills", DbType.String, model.MovieStills);
            db.AddInParameter(dbCommand, "MoviePrice", DbType.Decimal, model.MoviePrice);
            db.AddInParameter(dbCommand, "CityId", DbType.Int32, model.CityId);
            db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, model.TheaterId);
            db.AddInParameter(dbCommand, "TheaterName", DbType.String, model.TheaterName);
            db.AddInParameter(dbCommand, "AreaId", DbType.Int32, model.AreaId);
            db.AddInParameter(dbCommand, "MovieSeatTime", DbType.DateTime, model.MovieSeatTime);
            db.AddInParameter(dbCommand, "ScreeningsId", DbType.Int32, model.ScreeningsId);
            db.AddInParameter(dbCommand, "Price", DbType.Decimal, model.Price);
            if (trans != null)
            {
                return ExecuteNonQuery(db, dbCommand, trans);
            }
            else
            {
                return ExecuteNonQuery(db, dbCommand);
            }
        }

        /// <summary>
        /// 增加一条数据：自动屏蔽传入值为null的字段
        /// </summary>
        public int AddAutoCheck(Joyintech.Model.inpiao365.movieOnTheater model, DbTransaction trans = null)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into movieOnTheater(");
            if (model.MovieId != 0)
            {
                strSql.Append("MovieId,");
            }
            if (model.MovieName != "")
            {
                strSql.Append("MovieName,");
            }
            if (model.Director != "")
            {
                strSql.Append("Director,");
            }
            if (model.ToStar != "")
            {
                strSql.Append("ToStar,");
            }
            if (model.MovieType != "")
            {
                strSql.Append("MovieType,");
            }
            if (model.Country != "")
            {
                strSql.Append("Country,");
            }
            if (model.Trailer != 0)
            {
                strSql.Append("Trailer,");
            }
            if (model.ReleaseDate != new DateTime())
            {
                strSql.Append("ReleaseDate,");
            }
            if (model.MovieContent != "")
            {
                strSql.Append("MovieContent,");
            }
            if (model.MovieBehind != "")
            {
                strSql.Append("MovieBehind,");
            }
            if (model.MovieLogo != "")
            {
                strSql.Append("MovieLogo,");
            }
            if (model.MovieStills != "")
            {
                strSql.Append("MovieStills,");
            }
            if (model.MoviePrice != new decimal())
            {
                strSql.Append("MoviePrice,");
            }
            if (model.CityId != 0)
            {
                strSql.Append("CityId,");
            }
            if (model.TheaterId != 0)
            {
                strSql.Append("TheaterId,");
            }
            if (model.TheaterName != "")
            {
                strSql.Append("TheaterName,");
            }
            if (model.AreaId != 0)
            {
                strSql.Append("AreaId,");
            }
            if (model.MovieSeatTime != new DateTime())
            {
                strSql.Append("MovieSeatTime,");
            }
            if (model.ScreeningsId != 0)
            {
                strSql.Append("ScreeningsId,");
            }
            if (model.Price != new decimal())
            {
                strSql.Append("Price)");
            }
            if (strSql.ToString().EndsWith(","))
            {
                string sqlstr = strSql.ToString().Substring(0, strSql.ToString().Length - 1);
                strSql = new StringBuilder();
                strSql.Append(sqlstr + ")");
            }
            strSql.Append(" values (");
            if (model.MovieId != 0)
            {
                strSql.Append("@MovieId,");
            }
            if (model.MovieName != "")
            {
                strSql.Append("@MovieName,");
            }
            if (model.Director != "")
            {
                strSql.Append("@Director,");
            }
            if (model.ToStar != "")
            {
                strSql.Append("@ToStar,");
            }
            if (model.MovieType != "")
            {
                strSql.Append("@MovieType,");
            }
            if (model.Country != "")
            {
                strSql.Append("@Country,");
            }
            if (model.Trailer != 0)
            {
                strSql.Append("@Trailer,");
            }
            if (model.ReleaseDate != new DateTime())
            {
                strSql.Append("@ReleaseDate,");
            }
            if (model.MovieContent != "")
            {
                strSql.Append("@MovieContent,");
            }
            if (model.MovieBehind != "")
            {
                strSql.Append("@MovieBehind,");
            }
            if (model.MovieLogo != "")
            {
                strSql.Append("@MovieLogo,");
            }
            if (model.MovieStills != "")
            {
                strSql.Append("@MovieStills,");
            }
            if (model.MoviePrice != new decimal())
            {
                strSql.Append("@MoviePrice,");
            }
            if (model.CityId != 0)
            {
                strSql.Append("@CityId,");
            }
            if (model.TheaterId != 0)
            {
                strSql.Append("@TheaterId,");
            }
            if (model.TheaterName != "")
            {
                strSql.Append("@TheaterName,");
            }
            if (model.AreaId != 0)
            {
                strSql.Append("@AreaId,");
            }
            if (model.MovieSeatTime != new DateTime())
            {
                strSql.Append("@MovieSeatTime,");
            }
            if (model.ScreeningsId != 0)
            {
                strSql.Append("@ScreeningsId,");
            }
            if (model.Price != new decimal())
            {
                strSql.Append("@Price)");
            }
            if (strSql.ToString().EndsWith(","))
            {
                string str = strSql.ToString().Substring(0, strSql.ToString().Length - 1);
                strSql = new StringBuilder();
                strSql.Append(str + ")");
            }
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            if (model.MovieId != 0)
            {
                db.AddInParameter(dbCommand, "MovieId", DbType.Int32, model.MovieId);
            }
            if (model.MovieName != "")
            {
                db.AddInParameter(dbCommand, "MovieName", DbType.String, model.MovieName);
            }
            if (model.Director != "")
            {
                db.AddInParameter(dbCommand, "Director", DbType.String, model.Director);
            }
            if (model.ToStar != "")
            {
                db.AddInParameter(dbCommand, "ToStar", DbType.String, model.ToStar);
            }
            if (model.MovieType != "")
            {
                db.AddInParameter(dbCommand, "MovieType", DbType.String, model.MovieType);
            }
            if (model.Country != "")
            {
                db.AddInParameter(dbCommand, "Country", DbType.String, model.Country);
            }
            if (model.Trailer != 0)
            {
                db.AddInParameter(dbCommand, "Trailer", DbType.Int32, model.Trailer);
            }
            if (model.ReleaseDate != new DateTime())
            {
                db.AddInParameter(dbCommand, "ReleaseDate", DbType.DateTime, model.ReleaseDate);
            }
            if (model.MovieContent != "")
            {
                db.AddInParameter(dbCommand, "MovieContent", DbType.String, model.MovieContent);
            }
            if (model.MovieBehind != "")
            {
                db.AddInParameter(dbCommand, "MovieBehind", DbType.String, model.MovieBehind);
            }
            if (model.MovieLogo != "")
            {
                db.AddInParameter(dbCommand, "MovieLogo", DbType.String, model.MovieLogo);
            }
            if (model.MovieStills != "")
            {
                db.AddInParameter(dbCommand, "MovieStills", DbType.String, model.MovieStills);
            }
            if (model.MoviePrice != new decimal())
            {
                db.AddInParameter(dbCommand, "MoviePrice", DbType.Decimal, model.MoviePrice);
            }
            if (model.CityId != 0)
            {
                db.AddInParameter(dbCommand, "CityId", DbType.Int32, model.CityId);
            }
            if (model.TheaterId != 0)
            {
                db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, model.TheaterId);
            }
            if (model.TheaterName != "")
            {
                db.AddInParameter(dbCommand, "TheaterName", DbType.String, model.TheaterName);
            }
            if (model.AreaId != 0)
            {
                db.AddInParameter(dbCommand, "AreaId", DbType.Int32, model.AreaId);
            }
            if (model.MovieSeatTime != new DateTime())
            {
                db.AddInParameter(dbCommand, "MovieSeatTime", DbType.DateTime, model.MovieSeatTime);
            }
            if (model.ScreeningsId != 0)
            {
                db.AddInParameter(dbCommand, "ScreeningsId", DbType.Int32, model.ScreeningsId);
            }
            if (model.Price != new decimal())
            {
                db.AddInParameter(dbCommand, "Price", DbType.Decimal, model.Price);
            }
            if (trans != null)
            {
                return ExecuteNonQuery(db, dbCommand, trans);
            }
            else
            {
                return ExecuteNonQuery(db, dbCommand);
            }
        }

        /// <summary>
        /// 批量增加多条数据
        /// </summary>
        public int AddList(List<Joyintech.Model.inpiao365.movieOnTheater> list)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into movieOnTheater(");
            strSql.Append("MovieId,MovieName,Director,ToStar,MovieType,Country,Trailer,ReleaseDate,MovieContent,MovieBehind,MovieLogo,MovieStills,MoviePrice,CityId,TheaterId,TheaterName,AreaId,MovieSeatTime,ScreeningsId,Price)");

            strSql.Append(" values (");
            strSql.Append("@MovieId,@MovieName,@Director,@ToStar,@MovieType,@Country,@Trailer,@ReleaseDate,@MovieContent,@MovieBehind,@MovieLogo,@MovieStills,@MoviePrice,@CityId,@TheaterId,@TheaterName,@AreaId,@MovieSeatTime,@ScreeningsId,@Price)");

            Database db = this.CreateDatabase();
            List<DbCommand> listCommand = new System.Collections.Generic.List<DbCommand>();

            foreach (Joyintech.Model.inpiao365.movieOnTheater model in list)
            {
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                db.AddInParameter(dbCommand, "MovieId", DbType.Int32, model.MovieId);
                db.AddInParameter(dbCommand, "MovieName", DbType.String, model.MovieName);
                db.AddInParameter(dbCommand, "Director", DbType.String, model.Director);
                db.AddInParameter(dbCommand, "ToStar", DbType.String, model.ToStar);
                db.AddInParameter(dbCommand, "MovieType", DbType.String, model.MovieType);
                db.AddInParameter(dbCommand, "Country", DbType.String, model.Country);
                db.AddInParameter(dbCommand, "Trailer", DbType.Int32, model.Trailer);
                db.AddInParameter(dbCommand, "ReleaseDate", DbType.DateTime, model.ReleaseDate);
                db.AddInParameter(dbCommand, "MovieContent", DbType.String, model.MovieContent);
                db.AddInParameter(dbCommand, "MovieBehind", DbType.String, model.MovieBehind);
                db.AddInParameter(dbCommand, "MovieLogo", DbType.String, model.MovieLogo);
                db.AddInParameter(dbCommand, "MovieStills", DbType.String, model.MovieStills);
                db.AddInParameter(dbCommand, "MoviePrice", DbType.Decimal, model.MoviePrice);
                db.AddInParameter(dbCommand, "CityId", DbType.Int32, model.CityId);
                db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, model.TheaterId);
                db.AddInParameter(dbCommand, "TheaterName", DbType.String, model.TheaterName);
                db.AddInParameter(dbCommand, "AreaId", DbType.Int32, model.AreaId);
                db.AddInParameter(dbCommand, "MovieSeatTime", DbType.DateTime, model.MovieSeatTime);
                db.AddInParameter(dbCommand, "ScreeningsId", DbType.Int32, model.ScreeningsId);
                db.AddInParameter(dbCommand, "Price", DbType.Decimal, model.Price);
                listCommand.Add(dbCommand);
            }

            return this.ExecuteNonQueryListTran(db, listCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(Joyintech.Model.inpiao365.movieOnTheater model, DbTransaction trans = null)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update movieOnTheater set ");
            strSql.Append("MovieId=@MovieId,");
            strSql.Append("MovieName=@MovieName,");
            strSql.Append("Director=@Director,");
            strSql.Append("ToStar=@ToStar,");
            strSql.Append("MovieType=@MovieType,");
            strSql.Append("Country=@Country,");
            strSql.Append("Trailer=@Trailer,");
            strSql.Append("ReleaseDate=@ReleaseDate,");
            strSql.Append("MovieContent=@MovieContent,");
            strSql.Append("MovieBehind=@MovieBehind,");
            strSql.Append("MovieLogo=@MovieLogo,");
            strSql.Append("MovieStills=@MovieStills,");
            strSql.Append("MoviePrice=@MoviePrice,");
            strSql.Append("CityId=@CityId,");
            strSql.Append("TheaterId=@TheaterId,");
            strSql.Append("TheaterName=@TheaterName,");
            strSql.Append("AreaId=@AreaId,");
            strSql.Append("MovieSeatTime=@MovieSeatTime,");
            strSql.Append("ScreeningsId=@ScreeningsId,");
            strSql.Append("Price=@Price");
            strSql.Append(" where MovieId=@MovieId and TheaterId=@TheaterId ");
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "MovieId", DbType.Int32, model.MovieId);
            db.AddInParameter(dbCommand, "MovieName", DbType.String, model.MovieName);
            db.AddInParameter(dbCommand, "Director", DbType.String, model.Director);
            db.AddInParameter(dbCommand, "ToStar", DbType.String, model.ToStar);
            db.AddInParameter(dbCommand, "MovieType", DbType.String, model.MovieType);
            db.AddInParameter(dbCommand, "Country", DbType.String, model.Country);
            db.AddInParameter(dbCommand, "Trailer", DbType.Int32, model.Trailer);
            db.AddInParameter(dbCommand, "ReleaseDate", DbType.DateTime, model.ReleaseDate);
            db.AddInParameter(dbCommand, "MovieContent", DbType.String, model.MovieContent);
            db.AddInParameter(dbCommand, "MovieBehind", DbType.String, model.MovieBehind);
            db.AddInParameter(dbCommand, "MovieLogo", DbType.String, model.MovieLogo);
            db.AddInParameter(dbCommand, "MovieStills", DbType.String, model.MovieStills);
            db.AddInParameter(dbCommand, "MoviePrice", DbType.Decimal, model.MoviePrice);
            db.AddInParameter(dbCommand, "CityId", DbType.Int32, model.CityId);
            db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, model.TheaterId);
            db.AddInParameter(dbCommand, "TheaterName", DbType.String, model.TheaterName);
            db.AddInParameter(dbCommand, "AreaId", DbType.Int32, model.AreaId);
            db.AddInParameter(dbCommand, "MovieSeatTime", DbType.DateTime, model.MovieSeatTime);
            db.AddInParameter(dbCommand, "ScreeningsId", DbType.Int32, model.ScreeningsId);
            db.AddInParameter(dbCommand, "Price", DbType.Decimal, model.Price);
            if (trans != null)
            {
                return ExecuteNonQuery(db, dbCommand, trans);
            }
            else
            {
                return ExecuteNonQuery(db, dbCommand);
            }
        }

        /// <summary>
        /// 更新一条数据:自动忽略为null值的字段
        /// </summary>
        public int UpdateAutoCheck(Joyintech.Model.inpiao365.movieOnTheater model, DbTransaction trans = null)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update movieOnTheater set ");
            if (model.MovieId != 0)
            {
                strSql.Append("MovieId=@MovieId,");
            }
            if (model.MovieName != "")
            {
                strSql.Append("MovieName=@MovieName,");
            }
            if (model.Director != "")
            {
                strSql.Append("Director=@Director,");
            }
            if (model.ToStar != "")
            {
                strSql.Append("ToStar=@ToStar,");
            }
            if (model.MovieType != "")
            {
                strSql.Append("MovieType=@MovieType,");
            }
            if (model.Country != "")
            {
                strSql.Append("Country=@Country,");
            }
            if (model.Trailer != 0)
            {
                strSql.Append("Trailer=@Trailer,");
            }
            if (model.ReleaseDate != new DateTime())
            {
                strSql.Append("ReleaseDate=@ReleaseDate,");
            }
            if (model.MovieContent != "")
            {
                strSql.Append("MovieContent=@MovieContent,");
            }
            if (model.MovieBehind != "")
            {
                strSql.Append("MovieBehind=@MovieBehind,");
            }
            if (model.MovieLogo != "")
            {
                strSql.Append("MovieLogo=@MovieLogo,");
            }
            if (model.MovieStills != "")
            {
                strSql.Append("MovieStills=@MovieStills,");
            }
            if (model.MoviePrice != new decimal())
            {
                strSql.Append("MoviePrice=@MoviePrice,");
            }
            if (model.CityId != 0)
            {
                strSql.Append("CityId=@CityId,");
            }
            if (model.TheaterId != 0)
            {
                strSql.Append("TheaterId=@TheaterId,");
            }
            if (model.TheaterName != "")
            {
                strSql.Append("TheaterName=@TheaterName,");
            }
            if (model.AreaId != 0)
            {
                strSql.Append("AreaId=@AreaId,");
            }
            if (model.MovieSeatTime != new DateTime())
            {
                strSql.Append("MovieSeatTime=@MovieSeatTime,");
            }
            if (model.ScreeningsId != 0)
            {
                strSql.Append("ScreeningsId=@ScreeningsId,");
            }
            if (model.Price != new decimal())
            {
                strSql.Append("Price=@Price");
            }
            if (strSql.ToString().EndsWith(","))
            {
                string sqlstr = strSql.ToString().Substring(0, strSql.ToString().Length - 1);
                strSql = new StringBuilder();
                strSql.Append(sqlstr);
            }
            strSql.Append(" where MovieId=@MovieId and TheaterId=@TheaterId ");
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            if (model.MovieId != 0)
            {
                db.AddInParameter(dbCommand, "MovieId", DbType.Int32, model.MovieId);
            }
            if (model.MovieName != "")
            {
                db.AddInParameter(dbCommand, "MovieName", DbType.String, model.MovieName);
            }
            if (model.Director != "")
            {
                db.AddInParameter(dbCommand, "Director", DbType.String, model.Director);
            }
            if (model.ToStar != "")
            {
                db.AddInParameter(dbCommand, "ToStar", DbType.String, model.ToStar);
            }
            if (model.MovieType != "")
            {
                db.AddInParameter(dbCommand, "MovieType", DbType.String, model.MovieType);
            }
            if (model.Country != "")
            {
                db.AddInParameter(dbCommand, "Country", DbType.String, model.Country);
            }
            if (model.Trailer != 0)
            {
                db.AddInParameter(dbCommand, "Trailer", DbType.Int32, model.Trailer);
            }
            if (model.ReleaseDate != new DateTime())
            {
                db.AddInParameter(dbCommand, "ReleaseDate", DbType.DateTime, model.ReleaseDate);
            }
            if (model.MovieContent != "")
            {
                db.AddInParameter(dbCommand, "MovieContent", DbType.String, model.MovieContent);
            }
            if (model.MovieBehind != "")
            {
                db.AddInParameter(dbCommand, "MovieBehind", DbType.String, model.MovieBehind);
            }
            if (model.MovieLogo != "")
            {
                db.AddInParameter(dbCommand, "MovieLogo", DbType.String, model.MovieLogo);
            }
            if (model.MovieStills != "")
            {
                db.AddInParameter(dbCommand, "MovieStills", DbType.String, model.MovieStills);
            }
            if (model.MoviePrice != new decimal())
            {
                db.AddInParameter(dbCommand, "MoviePrice", DbType.Decimal, model.MoviePrice);
            }
            if (model.CityId != 0)
            {
                db.AddInParameter(dbCommand, "CityId", DbType.Int32, model.CityId);
            }
            if (model.TheaterId != 0)
            {
                db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, model.TheaterId);
            }
            if (model.TheaterName != "")
            {
                db.AddInParameter(dbCommand, "TheaterName", DbType.String, model.TheaterName);
            }
            if (model.AreaId != 0)
            {
                db.AddInParameter(dbCommand, "AreaId", DbType.Int32, model.AreaId);
            }
            if (model.MovieSeatTime != new DateTime())
            {
                db.AddInParameter(dbCommand, "MovieSeatTime", DbType.DateTime, model.MovieSeatTime);
            }
            if (model.ScreeningsId != 0)
            {
                db.AddInParameter(dbCommand, "ScreeningsId", DbType.Int32, model.ScreeningsId);
            }
            if (model.Price != new decimal())
            {
                db.AddInParameter(dbCommand, "Price", DbType.Decimal, model.Price);
            }
            if (trans != null)
            {
                return ExecuteNonQuery(db, dbCommand, trans);
            }
            else
            {
                return ExecuteNonQuery(db, dbCommand);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateList(List<Joyintech.Model.inpiao365.movieOnTheater> list)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update movieOnTheater set ");
            strSql.Append("MovieId=@MovieId,");
            strSql.Append("MovieName=@MovieName,");
            strSql.Append("Director=@Director,");
            strSql.Append("ToStar=@ToStar,");
            strSql.Append("MovieType=@MovieType,");
            strSql.Append("Country=@Country,");
            strSql.Append("Trailer=@Trailer,");
            strSql.Append("ReleaseDate=@ReleaseDate,");
            strSql.Append("MovieContent=@MovieContent,");
            strSql.Append("MovieBehind=@MovieBehind,");
            strSql.Append("MovieLogo=@MovieLogo,");
            strSql.Append("MovieStills=@MovieStills,");
            strSql.Append("MoviePrice=@MoviePrice,");
            strSql.Append("CityId=@CityId,");
            strSql.Append("TheaterId=@TheaterId,");
            strSql.Append("TheaterName=@TheaterName,");
            strSql.Append("AreaId=@AreaId,");
            strSql.Append("MovieSeatTime=@MovieSeatTime,");
            strSql.Append("ScreeningsId=@ScreeningsId,");
            strSql.Append("Price=@Price");
            strSql.Append(" where MovieId=@MovieId and TheaterId=@TheaterId ");

            Database db = this.CreateDatabase();
            List<DbCommand> listCommand = new System.Collections.Generic.List<DbCommand>();

            foreach (Joyintech.Model.inpiao365.movieOnTheater model in list)
            {
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                db.AddInParameter(dbCommand, "MovieId", DbType.Int32, model.MovieId);
                db.AddInParameter(dbCommand, "MovieName", DbType.String, model.MovieName);
                db.AddInParameter(dbCommand, "Director", DbType.String, model.Director);
                db.AddInParameter(dbCommand, "ToStar", DbType.String, model.ToStar);
                db.AddInParameter(dbCommand, "MovieType", DbType.String, model.MovieType);
                db.AddInParameter(dbCommand, "Country", DbType.String, model.Country);
                db.AddInParameter(dbCommand, "Trailer", DbType.Int32, model.Trailer);
                db.AddInParameter(dbCommand, "ReleaseDate", DbType.DateTime, model.ReleaseDate);
                db.AddInParameter(dbCommand, "MovieContent", DbType.String, model.MovieContent);
                db.AddInParameter(dbCommand, "MovieBehind", DbType.String, model.MovieBehind);
                db.AddInParameter(dbCommand, "MovieLogo", DbType.String, model.MovieLogo);
                db.AddInParameter(dbCommand, "MovieStills", DbType.String, model.MovieStills);
                db.AddInParameter(dbCommand, "MoviePrice", DbType.Decimal, model.MoviePrice);
                db.AddInParameter(dbCommand, "CityId", DbType.Int32, model.CityId);
                db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, model.TheaterId);
                db.AddInParameter(dbCommand, "TheaterName", DbType.String, model.TheaterName);
                db.AddInParameter(dbCommand, "AreaId", DbType.Int32, model.AreaId);
                db.AddInParameter(dbCommand, "MovieSeatTime", DbType.DateTime, model.MovieSeatTime);
                db.AddInParameter(dbCommand, "ScreeningsId", DbType.Int32, model.ScreeningsId);
                db.AddInParameter(dbCommand, "Price", DbType.Decimal, model.Price);
                listCommand.Add(dbCommand);
            }
            return this.ExecuteNonQueryListTran(db, listCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(int MovieId, int TheaterId, DbTransaction trans = null)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from movieOnTheater ");
            strSql.Append(" where MovieId=@MovieId and TheaterId=@TheaterId ");
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "MovieId", DbType.Int32, MovieId);
            db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, TheaterId);
            if (trans != null)
            {
                return ExecuteNonQuery(db, dbCommand, trans);
            }
            else
            {
                return ExecuteNonQuery(db, dbCommand);
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Joyintech.Model.inpiao365.movieOnTheater GetModel(int MovieId, int TheaterId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select MovieId,MovieName,Director,ToStar,MovieType,Country,Trailer,ReleaseDate,MovieContent,MovieBehind,MovieLogo,MovieStills,MoviePrice,CityId,TheaterId,TheaterName,AreaId,MovieSeatTime,ScreeningsId,Price from movieOnTheater ");
            strSql.Append(" where MovieId=@MovieId and TheaterId=@TheaterId ");
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "MovieId", DbType.Int32, MovieId);
            db.AddInParameter(dbCommand, "TheaterId", DbType.Int32, TheaterId);
            Joyintech.Model.inpiao365.movieOnTheater model = null;
            using (IDataReader dataReader = ExecuteReader(db, dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select MovieId,MovieName,Director,ToStar,MovieType,Country,Trailer,ReleaseDate,MovieContent,MovieBehind,MovieLogo,MovieStills,MoviePrice,CityId,TheaterId,TheaterName,AreaId,MovieSeatTime,ScreeningsId,Price ");
            strSql.Append(" FROM movieOnTheater ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = this.CreateDatabase();
            return ExecuteDataSet(db, CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListRunSql(string strSql)
        {
            Database db = this.CreateDatabase();
            return ExecuteDataSet(db, CommandType.Text, strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = this.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "movieOnTheater");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return ExecuteDataSet(db, dbCommand);
        }*/


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Joyintech.Model.inpiao365.movieOnTheater ReaderBind(IDataReader dataReader)
        {
            Joyintech.Model.inpiao365.movieOnTheater model = new Joyintech.Model.inpiao365.movieOnTheater();
            object ojb;
            ojb = dataReader["MovieId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MovieId = (int)ojb;
            }
            model.MovieName = dataReader["MovieName"].ToString();
            model.Director = dataReader["Director"].ToString();
            model.ToStar = dataReader["ToStar"].ToString();
            model.MovieType = dataReader["MovieType"].ToString();
            model.Country = dataReader["Country"].ToString();
            ojb = dataReader["Trailer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Trailer = (int)ojb;
            }
            ojb = dataReader["ReleaseDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReleaseDate = (DateTime)ojb;
            }
            model.MovieContent = dataReader["MovieContent"].ToString();
            model.MovieBehind = dataReader["MovieBehind"].ToString();
            model.MovieLogo = dataReader["MovieLogo"].ToString();
            model.MovieStills = dataReader["MovieStills"].ToString();
            ojb = dataReader["MoviePrice"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MoviePrice = (decimal)ojb;
            }
            ojb = dataReader["CityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CityId = (int)ojb;
            }
            ojb = dataReader["TheaterId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TheaterId = (int)ojb;
            }
            model.TheaterName = dataReader["TheaterName"].ToString();
            ojb = dataReader["AreaId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AreaId = (int)ojb;
            }
            ojb = dataReader["MovieSeatTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MovieSeatTime = (DateTime)ojb;
            }
            ojb = dataReader["ScreeningsId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ScreeningsId = (int)ojb;
            }
            ojb = dataReader["Price"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Price = (decimal)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

